package com.situ.web.controller;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@WebServlet("/life")
public class LifeServlet extends HttpServlet{
	
	public LifeServlet() {
		System.out.println("LifeServlet.LifeServlet()");
	}
	
	// initial
	@Override
	public void init() throws ServletException {
		super.init();
		System.out.println("LifeServlet.init()");
	}
	
	@Override
	protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		System.out.println("LifeServlet.service()");
		
		
		// 服务器返回给浏览器是通过response
		// 告诉浏览器使用utf-8进行解码
		resp.setContentType("text/html;charset=utf-8");
		PrintWriter printWriter  = resp.getWriter();
		printWriter.print("你好，Servlet");
		printWriter.close();
	}
	
	@Override
	public void destroy() {
		super.destroy();
		System.out.println("LifeServlet.destroy()");
	}
	
	
}
